#!/bin/sh

SMTP="smtps://smtp.gmail.com:465"
FROM="nuvoton.zy@gmail.com"
FROM_PASSWD="qwertyuiop,."
TO_LIST="xxxxxx@nuvoton.com "
MAIL_FILE="/tmp/text"
ALIAS_NAME=`awk -F[#=] '/^Alias/{print $2}' /mnt/skyeye/etc/msloader.conf`

if [ ! -f "$MAIL_FILE" ] ; then
	echo -e "From: SkyEye<"$FROM">\nTo: "$TO_LIST"\nSubject:["$ALIAS_NAME"] Check it out!\n" > "$MAIL_FILE"
	echo -e "Call for Help!\nSomething killed me!\n" >> "$MAIL_FILE"
	ifconfig -a >> "$MAIL_FILE"

	for TO in $TO_LIST
	do
		/mnt/skyeye/bin/curl --url "$SMTP" --ssl -k --mail-from "$FROM" --mail-rcpt "$TO" --upload-file "$MAIL_FILE" --user "$FROM":"$FROM_PASSWD" --anyauth -m 10
		RET_CODE=$?

		if [ "$RET_CODE" != 0 ] ; then
			echo "Failed to send mail to "$TO" with error code "$RET_CODE
		fi
	done
fi
